//
//  WebViewCell.m
//  PilotSeries
//
//  Created by 黄立强 on 16/4/6.
//  Copyright © 2016年 leon.huang. All rights reserved.
//

#import "PAWebViewCell.h"
#import "MBProgressHUD.h"
#import "AFNetworking.h"
@interface PAWebViewCell()





@end


@implementation PAWebViewCell

-(void)awakeFromNib{
     self.autoresizingMask = UIViewAutoresizingNone;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netStatusChanged:) name:AFNetworkingReachabilityDidChangeNotification object:nil];
       self.webView.scrollView.bounces = NO;
     self.webView.delegate = self;
    LOGMETHOD
}

- (void)webViewDidStartLoad:(UIWebView *)webView{
    LOGMETHOD
    [MBProgressHUD showHUDAddedTo:self animated:YES];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{


    [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
    [MBProgressHUD hideHUDForView:self animated:YES];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    DDLogError(@"webView didFailLoadWithError :%@",error);

    [MBProgressHUD hideHUDForView:self animated:YES];
}

-(void)dealloc{
    self.webView.delegate = nil;
    //断开连接
    [self.webView stringByEvaluatingJavaScriptFromString:@"disconnect();"];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    LOGMETHOD
}

-(void)netStatusChanged:(NSNotification *)notice{
  //网络状态变化
  NSInteger status = [notice.userInfo[AFNetworkingReachabilityNotificationStatusItem] integerValue];
    if (status ==0) {
        [self.webView stringByEvaluatingJavaScriptFromString:@"disconnect();"];
    }
}

@end
